package com.wangyk.jpaproject.service.impl;

import com.wangyk.jpaproject.repository.CategoryRepository;
import com.wangyk.jpaproject.service.CategoryService;
import com.wangyk.rabbitmqcommon.VO.ResultVO;
import com.wangyk.rabbitmqcommon.model.jpaproject.Category;
import com.wangyk.rabbitmqcommon.model.jpaproject.ProductInfo;
import com.wangyk.rabbitmqcommon.utils.ResultVOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService
{
    @Autowired
    private CategoryRepository categoryRepository;

    public List<Category> findAll()
    {
        return categoryRepository.findAll();
    }

    @Override
    public Category addCategory(Category category)
    {
        //save()方法先存储在缓存，saveAndFlush()立即生效。
        categoryRepository.saveAndFlush(category);
        //categoryRepository.save(category);
        return category;
    }

    @Override
    public Category updateCategory(Category category)
    {
        return null;
    }

    @Override
    public ResultVO findAllCategory()
    {
        ResultVO resultVO=new ResultVO();
        List<Category> categories=categoryRepository.findAll();
        resultVO.setData(categories);
        return ResultVOUtils.success(resultVO);
    }
}
